<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<title>部门管理</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" type="text/css"
	href="/resources/zTree/css/metroStyle/metroStyle.css">
<link rel="stylesheet" type="text/css"
	href="/resources/zTree/plugin/css/index.css">
<link rel="stylesheet" href="/resources/layui/css/layui.css" media="all" />
<link rel="stylesheet" href="/resources/css/public.css" media="all" />
<script type="text/javascript"
	src="/resources/zTree/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript"
	src="/resources/zTree/js/jquery.ztree.core.js"></script>
<script type="text/javascript"
	src="/resources/zTree/plugin/js/selectTree.js"></script>
</head>
<body class="childrenBody">

	<!-- 数据表格开始 -->
	<table class="layui-hide" id="userList" lay-filter="userList"></table>

	<div id="tableToolBar" style="display: none;" lay-filter="tableToolBar">
		<button type="button" class="layui-btn layui-btn-sm layui-btn-warm"
			lay-event="add">发帖</button>
	</div>

     <div id="toolBar" style="display: none;" lay-filter="toolBar">
         <button type="button" class="layui-btn  layui-btn-sm layui-btn-danger" lay-event="update">查看</button>
     </div>
	<!-- 数据表格结束 -->
	<script src="/resources/layui/layui.js" charset="utf-8"></script>

	<!-- 添加修改的弹出层  开始 -->
	<div style="display: none;" id="addAndUpdateUser">
		<form class="layui-form" id="dataFrm" lay-filter="dataFrm"
			style="margin: 10px">



			<div class="layui-form-item">
				<label class="layui-form-label">标题</label>
				<div class="layui-input-block">
					<input type="text" name="title" lay-verify="title"
						autocomplete="off" placeholder="请输入标题" class="layui-input">
				</div>
			</div>

			<div class="layui-form-item layui-form-text">
				<label class="layui-form-label">内容</label>
				<div class="layui-input-block">
					<textarea placeholder="请输入内容" id="content" name="content"
						class="layui-textarea"></textarea>
				</div>
			</div>


            <div class="layui-form-item">
                <label class="layui-form-label">作者</label>
                <div class="layui-input-block">
                    <input type="text" name="author"  lay-verify="title"
                           autocomplete="off" class="layui-input">
                </div>
            </div>



           <!--<div>-->

            <!--<form class="layui-form" id="mindataFrm" lay-filter="mindataFrm">-->

                <!--<div class="layui-form-item">-->
                    <!--<label class="layui-form-label">昵称</label>-->
                    <!--<div class="layui-input-block">-->
                        <!--<input type="text" name="author"  lay-verify="title"-->
                               <!--autocomplete="off" placeholder="请输入昵称" class="layui-input">-->
                    <!--</div>-->
                <!--</div>-->

                <!--<div class="layui-form-item layui-form-text">-->
                    <!--<label class="layui-form-label">内容</label>-->
                    <!--<div class="layui-input-block">-->
					<!--<textarea placeholder="请输入内容"  id="content" name="content"-->
                              <!--class="layui-textarea"></textarea>-->
                    <!--</div>-->
                <!--</div>-->
                <div class="layui-form-item" style="text-align: center;">
                    <div class="layui-input-block">
                        <button type="button" class="layui-btn" lay-submit=""
                                lay-filter="doSubmit">保存</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        <button type="back" class="layui-btn layui-btn-primary">返回</button>
                    </div>
                </div>

            <!--</form>-->
           <!--</div>-->
		</form>
            <!--   <div class="box">
                  评论发布: <textarea name="" id="b" cols="30" rows="10"></textarea><button id="a">发布</button>
                <ul style="list-style: none">
                    <li></li>
                    <li></li>
                    <li></li>
                </ul>
               </div>-->
        <form action="/insert/reply" >
           <div>昵称:<input type="text" id="author" name="author" /></div>
        <div>内容:<textarea placeholder="请输入内容" id="content" name="content" ></textarea></div>
            <button  id = "fa" value="发布">发布</button>
        </form>

	</div>
	<!-- 添加修改的弹出层  结束 -->


	<script type="text/javascript">
	var form;
	var tableIns;//数据表格实例
		layui.use([ 'element', 'layer', 'jquery', 'form', 'table','laydate' ],
				function() {
					var element = layui.element;
					var layer = layui.layer;
					var $ = layui.jquery;
					var laydate = layui.laydate;
					form = layui.form;
					var table = layui.table;
					var laydate=layui.laydate;
                    initDiv($("#aaa"));
                    //initDiv($("#nicheng"));
					initProviderSelect($("#searchid"));
					 tableIns=table.render({
					    elem: '#userList'  //指渲染的目标  
					    ,url:'/topic/loadAllTopic'//请求地址
					    ,cellMinWidth: 80 //全局定义常规单元格的最小宽度
					    ,height:'full-200'//设置高度    
					 	,page:true//开启分页
					 	,toolbar:"#tableToolBar"//设置显示工具条并设置表头左边的工具类
					 	,defaultToolbar:['filter','print']  //设置默认工具条的显示和顺序
					 	,id:"goodsListTable"
					    ,cols: [ [
					      ,{field:'title',  title: '标题'}
					      ,{field:'author',  title: '发帖人'}
					      ,{field:'createdate',  title: '发帖日期'}
					      ,{field:'clickamount',  title: '浏览量'}
					      ,{title: '操作', minWidth:185, templet:'#toolBar',fixed:"right"}
					    ] ]
					  });

					  //监听工具栏事件
                    table.on('tool(userList)', function(obj){

                        var data = obj.data; //获得当前行数据



                        switch(obj.event){
                            case 'update':
                                toUpdate(data);
                                break;

                        };
                    });


                    function initDiv(data) {
                        $.post("/queryAll/reply",function(obj){
                            var html="";
                            for(var i=0;i<obj.length;i++){

                                var o=obj[i];

                                    html+=("<input type='text'  value="+o.author+"   "+o.content+"   "+o.createdate+" />")

                            }
                            $("#aaa").html(html);
                            form.render();

                        });
                    }

                    //修改
                    function toUpdate(data){
                        url="/customer/updateCustomer";
                        index=layer.open({
                            type:1,//弹出层的类型
                            title:'修改用户',
                            content:$("#addAndUpdateUser"),  //type=1时使用
                            skin:'layui-layer-molv',//设置皮肤
                            area: ['500px', '300px'],//设置宽高
                            shade:0.5,//设置遮罩的透明度
                            shadeClose:true,//设置点击遮罩是否关闭弹出层
                            maxmin:true, //是否显示最大化和最小化的按钮  该参数值对type:1和type:2有效
                            success:function(){
                                form.val("dataFrm",data);

                            }
                        })
                    }


                    table.on('toolbar(userList)', function(obj){
						  var data = obj.data; //获得当前行数据
						    switch(obj.event){
						      case 'add':
						    	  laydate.render({
									    elem: '#billtime'
									    ,type: 'datetime'
									  });
						    	  toAdd();
						      break;
						    };
						  });
					  laydate.render({
							elem:"#hiredate",
							type:'datetime'
						})




					  
						function initProviderSelect(elem,fun){
				        	$.post("/bill/loadAllBill",function(obj){
				        		elem.html("<option value=''>请选择</option>");
				            	for(var i=0;i<obj.length;i++){
				            		var o=obj[i];
				            		
				            		elem.append("<option value="+o.id+" > "+o.name+" </option> ")
				            	}
				            	form.render("select");
				            	if(fun!= undefined ){
				            		fun();
				            	}
				            });
				        }
					var url="";
					var mainIndex;
					//添加
					  function toAdd(){
						  url="/topic/addTopic";
							index=layer.open({
								type:1,//弹出层的类型
								title:'添加用户',
								content:$("#addAndUpdateUser"),  //type=1时使用
								skin:'layui-layer-molv',//设置皮肤
								area: ['800px', '600px'],//设置宽高
								shade:0.5,//设置遮罩的透明度
								shadeClose:true,//设置点击遮罩是否关闭弹出层
								maxmin:true, //是否显示最大化和最小化的按钮  该参数值对type:1和type:2有效
								success:function(){
									
									$("#dataFrm")[0].reset();
									
									
									
								}
						})
					}
					//保存
					  form.on("submit(doSubmit)",function(obj){
						 
							$.post(url,obj.field,function(result){
								if(result.code>0){
									layer.msg(result.msg);

								}
								tableIns.reload();
								layer.close(index);
							})
							return false;//禁用同步提交方式
						});
						
						
				});

		/*//发评论
        var btn = document.getElementsById("#a");
        var txt = document.getElementById("#b");
        var ul = document.createElement("ul");
        btn.parentNode.appendChild(ul);
        btn.onclick = function () {
            if(txt.value == ""){
                alert("输入不能为空");
                return false;

            }
            var  newLi = document.createElement("li");
            newLi.innerHTML = txt.value + "<a href='javascript:;' id='c'>删除</a>";
            ul.appendChild(newLi);
            txt.value = "";
            var lis = ul.children;
            if(lis.length == 0){
                ul.appendChild(newLi);
            }else {
                ul.insertBefore(newLi,lis[0]);

            }
            var as = document.getElementById("#c");
            for (var i = 0 ;i <as.length;i++){
                as[i].click = function () {
                    ul.removeChild(this.parentNode);
                }
            }

        }
*/

	</script>

</body>
</html>